﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Windows;
using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Linq;
using WPFExcelReport.Helpers;
using System.Windows.Input;
using System.Windows.Controls;
namespace WPFExcelReport
{
    public partial class TEXHR
    {

        public TEXHR()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VHRSTAMM();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);

        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            switch (app.company)
            {
                default:
                    CHKWVERHR();
                    break;
            }
            base.QueryCommand(sender, e);
        }
        public void CHKWVERHR()
        {
            try
            {

                if (app.IsSQLDEMO)
                    return;
                
                SResult = TMV.QHRRTWVER2HR();
                dwData = TBMain.NewRow();
                TMV.SetUpNewRow(ref dwData);
                dwData["HRBGRP"] = "WV";
                TMV.DHRBGRP(dwData); 
                DataRow dwHRX = TMV.VHRX.TBMain.NewRow();
                TMV.VHRX.SetUpNewRow(ref dwHRX);
                dwHRX["UPDATER"] = "WV";
                
                foreach (DataRow row in SResult.Tables[0].Rows)
                {
                    string name = Helper.ConvertGB2312To8859P1(row["HRNNAME"].ToString()).Trim();
                    if (name == "")
                        continue;
                    dwData["HRITPNR"] = "RT" + Helpers.Helper.Right("000000" + row["HRBENID"].ToString().Trim(), 6);
                    dwData["HRBENID"] = Helpers.Helper.Left(row["HRBENID"].ToString().PadRight(8), 8);
                    dwData["HRNNAME"] = Helpers.Helper.Left(name.PadRight(40), 40);
                    TMV.InsertHRSTAMM(dwData); 
                    dwHRX["COMPANY"] = app.company;
                    dwHRX["ROWNID"] = VSDDAT.SD22.GETNEXT("0022", "  ", "HRSEQ", 1);
                    dwHRX["USERID"] = dwData["HRBENID"];
                    dwHRX["EXCELFILE"] = dwData["HRNNAME"];
                    TMV.VHRX.InsertICC_HRSTAMM(dwHRX);
                } 
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
    }
}
